#include "system_server_diagnosis.h"

#include <algorithm>
#include <future>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>

#include "base_file_util.h"
#include "base_utils.h"
#include "base_string.h"
#include "base_log.h"
#include "common_shell.h"
#include "base_memory_pool.h"
namespace El {
namespace SystemServer {

SystemServerDiagnosis &SystemServerDiagnosis::GetInstance()
{
    static SystemServerDiagnosis instance;
    return instance;
}

bool SystemServerDiagnosis::Start()
{
    Common::Shell::GetInstance().RegisterCommand(
        "mem", std::bind(&SystemServerDiagnosis::System, this, std::placeholders::_1));
    return true;
}

void SystemServerDiagnosis::System(const std::string &args)
{
    std::vector<std::string> vec_args;
    Base::Split(args, " ", vec_args);
    if (vec_args.size() < 1) {
        LOG_ERROR("Invalid args: {}", args.c_str());
        return;
    }

    std::string text = "";
    if (vec_args[0] == "dump") {
        Base::MemoryPool::GetInstance().DumpStatus(true);
    }
    LOG_INFO("生成文本完成: {}", text.c_str());
}

} // namespace SystemServer
} // namespace El